#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 1e5 + 10;

vector<pair<int, int>> v[4];

void work1(int n, int m, vector<pair<int, int>> &p) {
	int i = 1;
	while (i <= n) {
		for (int j = 1; j <= m; j++) p.push_back({ i, j });
		i += m;
	}
	for (int j = i - n + 1; j + i - n <= m; j++) p.push_back({ n, j });
}

void work2(int n, int m, vector<pair<int, int>> &p) {
	if (m + 1 <= n) {
		for (int i = 1; i <= m; i++) p.push_back({ 1, i }), p.push_back({ n, i });
		
		int mx = 1, res = 0;
		for (int i = m; i > 0; i -= 2) {
			int l = m / 2 + 1 + (i + 1) / 2;
			int r = n - m / 2 - (i + 1) / 2;
			int d = (r - l + i) / i * i;
			if (d > res) mx = i;
		}
		
		int l = m / 2 + 1 + (mx + 1) / 2;
		int r = n - m / 2 - (mx + 1) / 2;
		int d = (m - mx) / 2;

		for (int i = l; i <= r; i += mx) 
			for (int j = d + 1; j + d <= m; j++) p.push_back({ i, j });
	}
}

int f[N];

bool edmer;
signed main() {
	freopen("bishop.in", "r", stdin);
	freopen("bishop.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
    
	int n = read(), m = read();
	work1(n, m, v[0]), work1(m, n, v[1]);
	work2(n, m, v[2]), work2(m, n, v[3]);

	for (auto &l : v[1]) swap(l.first, l.second);
	for (auto &l : v[3]) swap(l.first, l.second);
	
	for (int i = 1; i < 4; i++) if (v[i].size() > v[0].size()) swap(v[i], v[0]);

	write(v[0].size()), putchar('\n');
	for (auto l : v[0]) write(l.first), putchar(' '), write(l.second), putchar('\n');


    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 